﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmsGui
{
    /// <summary>
    /// Class wraps the given T class so that it becomes a singleton. 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Singleton<T> where T : class, new()
    {
        private static T instance = null;
        public static T Instance
        {
            get
            {
                if (instance == null)
                    Instance = new T();
                return instance;
            }
            set
            {
                if (instance == null)
                    instance = value;
                if (instance != value)
                    throw new ArgumentException("Singleton for " + typeof(T).ToString());
            }
        }
    }

}
